import mysql from "mysql";

const dbConfig = {
 host: "127.0.0.1", // 本地
 port: 3306, // 端口
 user: "root", // 用户
 password: "root", // 密码
 database: "admin", //数据名称
};

const pool = mysql.createPool(dbConfig);

const query = (sql: string) => {
 return new Promise<any>((resolve, reject) => {
 pool.getConnection((error, connection) => {
 if (error) {
 reject(error);
 } else {
 connection.query(sql, (error, results) => {
if (error) {
 reject(error);
 } else {
 resolve(results);
 }
 connection.release(); // 释放该链接，把该链接放回池里供其他人使用
 });
 }
});
 });
};

export default query;
